LICENSE = "GPL-2.0-or-later"
require conf/license/license-gplv2.inc
require kodi-piers.inc

DEPENDS += " \
            zip-native \
            p8platform \
            kodi-platform \
            libtinyxml2 \
            jsoncpp \
            jsonrpc \
            boost \
            virtual/kodi \
          "

PACKAGE_ARCH = "${MACHINE}"

SRCREV_FORMAT = "pvr${KODIADDONPLUGIN}"

PVRMYTV = "${@bb.utils.contains("KODIADDONPLUGIN", "mythtv", "janbar", "kodi-pvr", d)}"

PVRGIT = "${PVRMYTV}"

SRC_URI = "git://github.com/${PVRGIT}/pvr.${KODIADDONPLUGIN}.git;destsuffix=pvr.${KODIADDONPLUGIN};name=pvr${KODIADDONPLUGIN};branch=${KODIADDONBRANCH};protocol=https"

inherit cmake pkgconfig gettext gitpkgv

S = "${UNPACKDIR}/pvr.${KODIADDONPLUGIN}"

OECMAKE_GENERATOR = "Unix Makefiles"

EXTRA_OECMAKE = " \
    -DADDONS_TO_BUILD=pvr.${KODIADDONPLUGIN} \
    -DADDON_SRC_PREFIX=${UNPACKDIR}/${BB_GIT_DEFAULT_DESTSUFFIX} \
    -DCMAKE_BUILD_TYPE=Debug -DVMTRACE=1 -DPARANOIA=1 \
    -DCMAKE_INSTALL_PREFIX=${datadir}/kodi/addons \
    -DKODI_INCLUDE_DIR=${STAGING_INCDIR}/kodi \
    -DCMAKE_MODULE_PATH='${STAGING_DIR_HOST}${libdir}/kodi;${STAGING_DIR_HOST}${datadir}/kodi/cmake' \
    -DCMAKE_PREFIX_PATH=${STAGING_DIR_HOST}${prefix} \
    -DJSONCPP_INCLUDE_DIRS=${STAGING_INCDIR}/json \
    -DPACKAGE_ZIP=1 \
    -DXLOCALE_NOT_USED=1 \
"

do_compile:prepend() {
	sed -i -e 's:I/usr/include:I${STAGING_INCDIR}:g' \
	       -e 's:-pipe:${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} -pipe:g' \
		   -e 's:/recipe-sysroot-native/usr/include:/recipe-sysroot/usr/include:g' \
	          ${B}/CMakeFiles/*/flags.make
	sed -i -e 's:-pipe:${HOST_CC_ARCH} ${TOOLCHAIN_OPTIONS} -pipe:g'\
	          ${B}/CMakeFiles/*/link.txt
}


# Make zip package for manual installation
do_install:append() {
	install -d ${D}${datadir}/kodi/addons/packages/
	( cd ${D}${datadir}/kodi/addons
	  zip -r ${D}${datadir}/kodi/addons/packages/pvr.${KODIADDONPLUGIN}-${PV}.zip pvr.${KODIADDONPLUGIN} -x '*.debug*' )
}

# Doesn't get added automagically, dlopen()?
RDEPENDS:${PN} += "libkodiplatform"

INSANE_SKIP:${PN} = "dev-so file-rdeps"
FILES:${PN} += "${datadir}/kodi"
FILES:${PN}-dbg += "${datadir}/kodi/addons/*/.debug/"

do_qa_staging() {
}
